import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const TUserInfo = "userInfo";
const TPowerList = 'power_list';
const TEnterTime = 'enter_time';

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUserInfo() {
  return JSON.parse(localStorage.getItem(TUserInfo));
}
export function hasIt(itemName) {
  var powerList = JSON.parse(sessionStorage.getItem(TPowerList));
  if (powerList == null || powerList.indexOf(itemName) === -1) {
    return false;
  } else {
    return true;
  }
}

export function getEnterTime() {
  return JSON.parse(sessionStorage.getItem(TEnterTime));
}
export function setEnterTime(token) {
  return sessionStorage.setItem(TEnterTime, token);
}
export default {
  enterTime: getEnterTime
};
